//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_handleDamage2.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

_unit = _this select 0;
_enemy  = _this select 3;
_damage = _this select 2;
_part   = _this select 1;
if (_damage > 0) then
{
	switch (true) do
	{
		case (_part == "legs")   : {BTC_r_damage_legs = BTC_r_damage_legs + (_damage * 1.5);BTC_r_damage = BTC_r_damage + (_damage / 3);};
		case (_part == "hand_l") : {BTC_r_damage_hands = BTC_r_damage_hands + _damage;BTC_r_damage = BTC_r_damage + (_damage / 3);};
		case (_part == "hand_2") : {BTC_r_damage_hands = BTC_r_damage_hands + _damage;BTC_r_damage = BTC_r_damage + (_damage / 3);};
		case (_part == "body")   : {BTC_r_damage = BTC_r_damage + ((_damage / 3) * 2);};
		case (_part == "head")   : {BTC_r_head = BTC_r_head + _damage;BTC_r_damage = BTC_r_damage + _damage;};
		case (_part == "" && BTC_r_hit != time)       : {BTC_r_damage = BTC_r_damage + (_damage / 2);};//What the hell
	};
};
if (Alive _unit && format ["%1", _unit getVariable "BTC_need_revive"] == "0") then
{
	if (BTC_respawn_gear == 1) then {
		BTC_gear = [_unit] call BTCR_fnc_getGear;
		TRACE_1("BTC_Gear",BTC_gear);
	};
	if (BTC_r_damage > 1.5 || (BTC_r_head > 1.2)) then {if (BTC_r_wait_for_revive == 1) then {[_unit] spawn BTCR_fnc_waitForRevive;} else {_unit setDamage 1;};};
	if (!BTC_r_bleeding_loop && BTC_r_damage > 0.3) then {[_unit] spawn BTCR_fnc_bleeding;};
	if (BTC_r_bleeding_loop && BTC_r_hit != time) then {_unit setVariable ["BTC_r_status",[(_unit getVariable "BTC_r_status" select 0),(((_unit getVariable "BTC_r_status") select 1) + (_damage * 5)),(_unit getVariable "BTC_r_status" select 2),(_unit getVariable "BTC_r_status" select 3),(_unit getVariable "BTC_r_status" select 4)],false]};
};
if ((BTC_r_damage > 0.5 && ((_unit getVariable "BTC_r_status" select 2) != 1)) && (BTC_r_damage > 0.7 && ((_unit getVariable "BTC_r_status" select 4) != 1))) then {_unit setVariable ["BTC_r_status",[((_unit getVariable "BTC_r_status") select 0),(_unit getVariable "BTC_r_status" select 1),1,(_unit getVariable "BTC_r_status" select 3),1],true];}
else
{
	if (BTC_r_damage > 0.5 && ((_unit getVariable "BTC_r_status" select 2) != 1)) then {_unit setVariable ["BTC_r_status",[((_unit getVariable "BTC_r_status") select 0),(_unit getVariable "BTC_r_status" select 1),1,(_unit getVariable "BTC_r_status" select 3),(_unit getVariable "BTC_r_status" select 4)],true];};
	if (BTC_r_damage > 0.7 && ((_unit getVariable "BTC_r_status" select 3) != 1)) then {_unit setVariable ["BTC_r_status",[((_unit getVariable "BTC_r_status") select 0),(_unit getVariable "BTC_r_status" select 1),(_unit getVariable "BTC_r_status" select 2),(_unit getVariable "BTC_r_status" select 3),1],true];};
};
BTC_r_hit = time;
_unit setDamage 0;

TRACE("End");